NodeList.prototype.forEach = Array.prototype.forEach;
var imagesArr = [];
(function () {
    // 项目基本信息 - dom 查询
    var customerName__solution = document.getElementById('customerName__solution'),
        contacts__solution = document.getElementById('contacts__solution'),
        regionCode__solution = document.getElementById('regionCode__solution'),
        address__solution = document.getElementById('address__solution'),

        // 屋面结构 - dom 查询
        wmjg__solution = document.getElementById('wmjg__solution'),

        // 安装布线 - 组件布线 - dom 查询
        zjbx__solution = document.getElementById('zjbx__solution'),

        // 防雷接地
        fljd__solution = document.getElementById('fljd__solution'),

        // 产品包 - 产品包物料编码 - dom 查询
        product_model__solution = document.getElementById('product_model__solution'),
        modules_num__solution = document.getElementById('modules_num__solution'),

        // 产品包 - 导轨 - dom 查询
        dg_1a__solution = document.getElementById('dg_1a__solution'),
        dg_2a__solution = document.getElementById('dg_2a__solution'),
        dg_3a__solution = document.getElementById('dg_3a__solution'),
        dg_1b__solution = document.getElementById('dg_1b__solution'),
        dg_2b__solution = document.getElementById('dg_2b__solution'),

        // 产品包 - 组串参数 - dom 查询
        zc_num__solution = document.getElementById('zc_num__solution'),
        zc1_cpts_num__solution = document.getElementById('zc1_cpts_num__solution'),
        zc2_cpts_num__solution = document.getElementById('zc2_cpts_num__solution'),
        zc3_cpts_num__solution = document.getElementById('zc3_cpts_num__solution'),
        zc4_cpts_num__solution = document.getElementById('zc4_cpts_num__solution'),

        // 物料清单 - 逆变器 - dom 查询
        inverter1__solution = document.getElementById('inverter1__solution'),
        inverter2__solution = document.getElementById('inverter2__solution'),

        // 物料清单 - 支架 - dom 查询
        zj_1a__solution = document.getElementById('zj_1a__solution'),
        zj_2a__solution = document.getElementById('zj_2a__solution'),
        zj_3a__solution = document.getElementById('zj_3a__solution'),
        zj_1b__solution = document.getElementById('zj_1b__solution'),
        zj_2b__solution = document.getElementById('zj_2b__solution'),
        jiaju_qty__solution = document.getElementById('jiaju_qty__solution'),
        guagou_qty__solution = document.getElementById('guagou_qty__solution'),
        zyk__solution = document.getElementById('zyk__solution'),
        byk__solution = document.getElementById('byk__solution'),
        ddp__solution = document.getElementById('ddp__solution'),
        jdj__solution = document.getElementById('jdj__solution'),

        // 物料清单 - 交流配电箱 - dom 查询
        pdx__solution = document.getElementById('pdx__solution'),

        // 物料清单 - 其他 - dom 查询
        zldl__solution = document.getElementById('zldl__solution'),
        jldl__solution = document.getElementById('jldl__solution'),
        hgjt__solution = document.getElementById('hgjt__solution'),
        fc__solution = document.getElementById('fc__solution');

    //获取url中的参数
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    var Request = new Object();
    Request = GetRequest();
    console.log(Request['projectId']);

    // 获取 json 数据
    if(typeof (Request['projectId']) == "undefined"){
        var path__solution = 'http://pm.ht-home.cn/api/others/getDesignInfoForShare.json?projectId=' + window.currentProjectId;
    }else{
        var path__solution = 'http://pm.ht-home.cn/api/others/getDesignInfoForShare.json?projectId=' + Request['projectId'];
    }
    var xhr__solution = new XMLHttpRequest();
    xhr__solution.open('GET', path__solution, true);
    xhr__solution.send(null);
    xhr__solution.onreadystatechange = function () {
        if (xhr__solution.readyState === 4) {
            if (xhr__solution.status === 200) {
                var jsonData = JSON.parse(xhr__solution.responseText),
                    hasPicture = false;
                function insertImg(classStr) {
                    var element = document.getElementsByClassName(classStr);
                    // 图片 - 数据
                    if (jsonData.data.classList.length) {
                        jsonData.data.classList.forEach(function (list, index) {
                            if (typeof (list[classStr]) !== 'undefined') {
                                list[classStr].forEach(function (image, index) {
                                    var newNode = document.createElement('li');
                                    newNode.className = 'sub-content';
                                    var str = '';
                                    str += '<img onclick="useHammer_html(event, ' + index + ')" class="' + classStr + 'image" class="image" src="';
                                    str += image.smallImageUrl;
                                    str += '" alt="">';
                                    imagesArr.push(image.largeImageUrl);
                                    newNode.innerHTML = str;
                                    element[0].appendChild(newNode);
                                    hasPicture = true;
                                });
                            } else {
                                console.log('json 文件中 list[classStr] 未定义');
                                hasPicture = false;
                            }
                        });
                    }

                    // 图片 - 大小
                    if (hasPicture) {
                        var images = document.querySelectorAll('.' + classStr + 'image'),
                            vw = document.body.clientWidth,
                            imageWidth = vw * 0.3;
                        marginTop = (vw - imageWidth * 3) / 4;
                        images.forEach(function (image) {
                            image.parentNode.style.height = imageWidth + 'px';
                            image.parentNode.style.marginTop = marginTop + 'px';
                        });
                        images[images.length - 1].parentNode.style.marginBottom = marginTop + 'px';
                    }
                }

                insertImg('NBQAZWZ');

                // 项目基本信息 - 数据插入
                 var cusData = jsonData.data.customerMsg;
                customerName__solution.innerHTML = typeof(cusData.customerName) === 'undefined' ? '' :cusData.customerName ;
                contacts__solution.innerHTML = typeof(cusData.contacts) === 'undefined' ? '' :cusData.contacts;
                regionCode__solution.innerHTML = typeof(cusData.regionCode) === 'undefined' ? '' :cusData.regionCode ;
                address__solution.innerHTML = typeof(cusData.address) === 'undefined' ? '' :cusData.address ;

                // 屋面结构 - 数据插入
                if (jsonData.data.spmsSurveyWmList.length) {
                    jsonData.data.spmsSurveyWmList.forEach(function (sswl, index) {
                        var newNode = document.createElement('li');
                        newNode.className = 'sub-content';
                        var str = '';
                        str += '<ul><li class="sub-header"><span class="title">屋面 ';
                        str += index + 1;
                        str += '</span></li><div class="line line-short"></div><li class="same-style-content sub-content"><span class="content-left">屋面倾角</span><span class="content-right">';
                        str += typeof (sswl.wmqj) === 'undefined' ? '' : sswl.wmqj;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋顶朝向</span><span class="content-right">';
                        str += typeof (sswl.wdcx) === 'undefined' ? '' : sswl.wdcx;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋面尺寸长</span><span class="content-right">';
                        str += typeof (sswl.wmLong) === 'undefined' ? '' : sswl.wmLong;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋面尺寸宽</span><span class="content-right">';
                        str += typeof (sswl.wmWeith) === 'undefined' ? '' : sswl.wmWeith;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">女儿墙高度</span><span class="content-right">';
                        str += typeof (sswl.nrqHeigth) === 'undefined' ? '' : sswl.nrqHeigth;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋面凸起物遮挡情况</span><span class="content-right">';
                        str += typeof (sswl.wmtq) === 'undefined' ? '' : sswl.wmtq;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋面厚度</span><span class="content-right">';
                        str += typeof (sswl.wmhd) === 'undefined' ? '' : sswl.wmhd;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">防水方案</span><span class="content-right">';
                        str += typeof (sswl.fsfa) === 'undefined' ? '' : sswl.fsfa;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">屋面形状</span><span class="content-right">';
                        str += typeof (sswl.wmxz) === 'undefined' ? '' : sswl.wmxz;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">本屋面屋顶类型</span><span class="content-right">';
                        str += typeof (sswl.bwwdlx) === 'undefined' ? '' : sswl.bwwdlx;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">可用尺寸(长)</span><span class="content-right">';
                        str += typeof (sswl.ableLong) === 'undefined' ? '' : sswl.ableLong;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">可用尺寸(宽)</span><span class="content-right">';
                        str += typeof (sswl.ableWeith) === 'undefined' ? '' : sswl.ableWeith;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">安装方向</span><span class="content-right">';
                        str += typeof (sswl.azfx) === 'undefined' ? '' : sswl.azfx;
                        // str += '</span></li>';
                        // str += '<li class="same-style-content sub-content"><span class="content-left">排布图</span><span class="content-right">';
                        // str += typeof (sswl.arrPhoto) === 'undefined' ? '' : sswl.arrPhoto;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">组件数量</span><span class="content-right">';
                        str += typeof (sswl.zjsl) === 'undefined' ? '' : sswl.zjsl;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">安装倾角</span><span class="content-right">';
                        str += typeof (sswl.azqj) === 'undefined' ? '' : sswl.azqj.substring(3, sswl.azqj.length);
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">组件间距</span><span class="content-right">';
                        str += typeof (sswl.zjjl) === 'undefined' ? '' : sswl.zjjl;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">女儿墙距离</span><span class="content-right">';
                        str += typeof (sswl.neqjl) === 'undefined' ? '' : sswl.neqjl;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">东西方向女儿墙距离</span><span class="content-right">';
                        str += typeof (sswl.ewneqjl) === 'undefined' ? '' : sswl.ewneqjl;
                        str += '</span></li>';
                        str += '<li class="same-style-content sub-content"><span class="content-left">安装数量</span><span class="content-right">';
                        str += typeof (sswl.azsl) === 'undefined' ? '' : sswl.azsl;
                        str += '</span></li>';
                        str += '</ul>';
                        newNode.innerHTML = str;
                        wmjg.appendChild(newNode);
                    });
                }

                // 安装布线 - 组件布线 - 数据插入
                var zjbxStr = '以';
                zjbxStr += jsonData.data.layoutOption1 || '( )';
                zjbxStr += '方式进行布线,从';
                zjbxStr += jsonData.data.layoutOption2 || '( )';
                zjbxStr += jsonData.data.layoutOption3 || '( )';
                zjbxStr += '通到';
                zjbxStr += jsonData.data.layoutOption4 || '( )';
                zjbxStr += ',并网在用户配电箱';
                zjbx__solution.innerHTML = zjbxStr;

                // 防雷接地

                fljd__solution.innerHTML = typeof( jsonData.data.fljd ) === 'undefined' ? '' :  jsonData.data.fljd ;

                // 产品包 - 产品包物料编码 - 数据插入
                product_model__solution.innerHTML = typeof( jsonData.data.productModel ) === 'undefined' ? '' :  jsonData.data.productModel ;
                modules_num__solution.innerHTML = typeof( jsonData.data.modulesNum ) === 'undefined' ? '' :  jsonData.data.modulesNum ;

                // 产品包 - 导轨 - 数据插入
                dg_1a__solution.innerHTML = typeof (jsonData.data.dg1a) === 'undefined' ? '0' : jsonData.data.dg1a;
                dg_2a__solution.innerHTML = typeof (jsonData.data.dg2a) === 'undefined' ? '0' : jsonData.data.dg2a;
                dg_3a__solution.innerHTML = typeof (jsonData.data.dg3a) === 'undefined' ? '0' : jsonData.data.dg3a;
                dg_1b__solution.innerHTML = typeof (jsonData.data.dg1b) === 'undefined' ? '0' : jsonData.data.dg1b;
                dg_2b__solution.innerHTML = typeof (jsonData.data.dg2b) === 'undefined' ? '0' : jsonData.data.dg2b;

                // 产品包 - 组串参数 - 数据插入
                zc_num__solution.innerHTML = typeof (jsonData.data.zcNum) === 'undefined' ? '0' : jsonData.data.zcNum;
                zc1_cpts_num__solution.innerHTML = typeof (jsonData.data.zc1CptsNum) === 'undefined' ? '0' : jsonData.data.zc1CptsNum;
                zc2_cpts_num__solution.innerHTML = typeof (jsonData.data.zc2CptsNum) === 'undefined' ? '0' : jsonData.data.zc2CptsNum;
                zc3_cpts_num__solution.innerHTML = typeof (jsonData.data.zc3CptsNum) === 'undefined' ? '0' : jsonData.data.zc3CptsNum;
                zc4_cpts_num__solution.innerHTML = typeof (jsonData.data.zc4CptsNum) === 'undefined' ? '0' : jsonData.data.zc4CptsNum;

                // 物料清单 - 逆变器 - 数据插入
                if (typeof (jsonData.data.inverter1) === 'undefined' || jsonData.data.inverter1 === '') {
                    inverter1__solution.parentElement.style.display = 'none';
                } else {
                    inverter1__solution.innerHTML = jsonData.data.inverter1;
                }
                if (typeof (jsonData.data.inverter2) === 'undefined' || jsonData.data.inverter2 === '') {
                    inverter2__solution.parentElement.style.display = 'none';
                } else {
                    inverter2__solution.innerHTML = jsonData.data.inverter2;
                }

                // 物料清单 - 支架 - 数据插入
                zj_1a__solution.innerHTML = typeof (jsonData.data.zj1a) === 'undefined' ? '0' : jsonData.data.zj1a;
                zj_2a__solution.innerHTML = typeof (jsonData.data.zj2a) === 'undefined' ? '0' : jsonData.data.zj2a;
                zj_3a__solution.innerHTML = typeof (jsonData.data.zj3a) === 'undefined' ? '0' : jsonData.data.zj3a;
                zj_1b__solution.innerHTML = typeof (jsonData.data.zj1b) === 'undefined' ? '0' : jsonData.data.zj1b;
                zj_2b__solution.innerHTML = typeof (jsonData.data.zj2b) === 'undefined' ? '0' : jsonData.data.dg2b;
                jiaju_qty__solution.innerHTML = typeof (jsonData.data.jiajuQty) === 'undefined' ? '0' : jsonData.data.jiajuQty;
                guagou_qty__solution.innerHTML = typeof (jsonData.data.guagouQty) === 'undefined' ? '0' : jsonData.data.guagouQty;
                zyk__solution.innerHTML = typeof (jsonData.data.zyk) === 'undefined' ? '0' : jsonData.data.zyk;
                byk__solution.innerHTML = typeof (jsonData.data.byk) === 'undefined' ? '0' : jsonData.data.byk;
                ddp__solution.innerHTML = typeof (jsonData.data.ddp) === 'undefined' ? '0' : jsonData.data.ddp;
                jdj__solution.innerHTML = typeof (jsonData.data.jdj) === 'undefined' ? '0' : jsonData.data.jdj;

                // 物料清单 - 交流配电箱 - 数据插入
                pdx__solution.innerHTML = typeof (jsonData.data.pdx) === 'undefined' ? '' : jsonData.data.pdx;

                // 物料清单 - 其他 - 数据插入
                zldl__solution.innerHTML = typeof (jsonData.data.zldl) === 'undefined' ? '' : jsonData.data.zldl;
                jldl__solution.innerHTML = typeof (jsonData.data.jldl) === 'undefined' ? '' : jsonData.data.jldl;
                hgjt__solution.innerHTML = typeof (jsonData.data.hgjt) === 'undefined' ? '' : jsonData.data.hgjt;
                fc__solution.innerHTML = typeof (jsonData.data.others) === 'undefined' ? '' : jsonData.data.others;
            }
        }
    };

})();

function useHammer_html(e, index) {
    var mask = document.getElementById('hammer-mask_html'),
        bg = document.getElementById('hammer-bg_html'),
        box = document.getElementById('hammer-box_html'),
        page = document.getElementById('hammer-page_html'),
        img = document.getElementById('image-big_html');

    window.initHammer_html(mask, bg, box, page, img);
    window.showHammer_html(imagesArr, index);
}
